package com.jt.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * direct路由模式配置
 **/
@Configuration
public class RabbitmqConfig_RouterKey {

    public static final String DIRECT_EXCHANGE = "direct_liushuhong";
    public static final String QUEUE_DIRECT1 = "QUEUE_DIRECT1";
    public static final String QUEUE_DIRECT2 = "QUEUE_DIRECT2";


    @Bean
    public Exchange exchange1() {
        return ExchangeBuilder.directExchange(DIRECT_EXCHANGE).durable(true).build();
    }

    @Bean
    public Queue queue_direct1() {
        //创建一个队列队列，并指定队列的名字
        return new Queue(QUEUE_DIRECT1, true);
    }

    @Bean
    public Queue queue_direct2() {
        //创建一个队列队列，并指定队列的名字
        return new Queue(QUEUE_DIRECT2, true);
    }


    @Bean
    public Binding setDirectExchange1() {
        //指定routingkey
        return BindingBuilder.bind(queue_direct1()).to(exchange1()).with("one").noargs();

    }

    @Bean
    public Binding setDirectExchange2() {
        //fanout模式不指定routingkey
        return BindingBuilder.bind(queue_direct2()).to(exchange1()).with("two").noargs();

    }
}
